package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderMapper {

    /**
     * 添加订单信息
     * @param orders
     */
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into orders values(null,#{number},#{status},#{userId},#{addressBookId},#{orderTime},#{checkoutTime}," +
            "#{payMethod},#{payStatus},#{amount},#{remark},#{phone},#{address},#{userName},#{consignee}" +
            ",#{cancelReason},#{rejectionReason},#{cancelTime},#{estimatedDeliveryTime},#{deliveryStatus}," +
            "#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    void insert(Orders orders);

    /**
     * 修改订单支付方式
     * @param dto
     */
    @Update("update orders set pay_method = #{payMethod} where number = #{orderNumber}")
    void updatePayMethod(OrdersPaymentDTO dto);

    /**
     * 根据分页条件查询订单信息
     * @param dto
     * @return
     */
    Page<Orders> findByPageQuery(OrdersPageQueryDTO dto);

    /**
     * 根据订单id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders findById(Long id);

    /**
     * 取消订单
     * @param orders
     */
    @Update("update orders set status = #{status}, cancel_reason = #{cancelReason}, cancelTime = #{cancelTime} where id = #{id}")
    void updateCancelOrdersById(Orders orders);

}
